﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace UT_AMS_UI_Controls
{
    public partial class FrmPagedGrid : Form
    {
        public FrmPagedGrid()
        {
            InitializeComponent();
            grid.Init("UserManager");
        }

        DataTable dt = new DataTable();
        const int TotalCount = 999;
        private void GetPagedTable()
        {
            grid.Preload();
            if (dt.Columns.Count == 0)
            {
                dt.Columns.Add("Name", typeof(string));
                dt.Columns.Add("Sex", typeof(string));
                dt.Columns.Add("Age", typeof(string));
                dt.Columns.Add("Status", typeof(string));
                dt.Columns.Add("Notes", typeof(string));
            }

            int count = grid.PageSize;
            int start = grid.PageSize * grid.CurrentPageIndex;
            int end = start + grid.PageSize;
            if (end > TotalCount)
            {
                end = TotalCount;
            }

            dt.Rows.Clear();
            for (int i = start; i < end; i++)
            {
                dt.Rows.Add("xiaoming" + i.ToString(), "1", "25", "unmarried" + i.ToString(), "现金管理子系统交易改动只涉及到头文件添加");
            }
        }

        void DoDataBind()
        {
            grid.Preload();
            GetPagedTable();
            dt.DefaultView.AllowNew = false;
            dt.DefaultView.AllowEdit = false;
            dt.DefaultView.AllowDelete = false;

            grid.DataBind(dt);
            grid.RecordCount = TotalCount;
        }

        private void amsGrid1_PageIndexChanged(object sender, EventArgs e)
        {
            DoDataBind();
        }

        private void btnLoadData_Click(object sender, EventArgs e)
        {
            DoDataBind();
        }
    }
}
